class: center, middle, inverse, title-slide .title[ # Work as a Team — under Version Control ] .subtitle[ ## Learn how to leverage Github in your work ] .date[ ###
] --- # Learning objectives .pull-left[ * Understand Git workflow * See git good practices * use github as a portfolio to ease work discovery ] .pull-right[ .img75[] ] --- ## Git Version control Create an account on Github - https://github.com/join? install Github desktop https://desktop.github.com/ .pull-left[ ] .pull-right[ .img75[] ] --- ## Git workflow Master Branch .pull-left[ ] .pull-right[ .img75[] ] --- ## Git - what Free: you don't need to pay to use any functionality Open source: Anyone can modify or contribute to the Git code Distributed: run Git on your local machine... all machines maintain a copy of the action history (commits) and can be synchronized at any time. Version Control: save changes made to one (or several) file(s) over time. makes it easy to go back to previous versions (time travel) and coordinate several people working on the same file/project .pull-left[ ] .pull-right[ .img75[] ] --- ## Git - when Have you changed a code and now it doesn't run/compile anymore? go back to the previous version with one (or two) commands on the terminal Do you want to avoid the previous situation altogether? use "branches" to make and test the changes before deploying the new code to production. Do you want to guarantee the integrity of the code in production? use pull requests reviewed by at least another team member Do you want to keep a history of the contributions each member made to the project and its evolution? .pull-left[ ] .pull-right[ .img75[] ] --- ## Git - why Collaboration Agility Application integrity Privacy .pull-left[ ] .pull-right[ .img75[] ] --- ## Git - dos Commit often Make your checkpoints Do not commit incomplete code Break the task into several small sub-tasks Commit only related work Write descriptive/meaningful commit messages Limit your subject to 50 character The commit message must complete the sentence "This commit ..." Use the body of the message to explain “what” and “why”, not “how” Test your code before pushing Use branches Update the master code with pull requests .pull-left[ ] .pull-right[ .img75[] ] --- ## Git - Don’ts Don’t git push straight to master. Create branches! Do not commit files that can be regenerated (e.g. binary, graphs) Do not commit configuration files (e.g. “.vscode/”, access tokens) Do not change a repository's public history Avoid rewriting the master’s history. .pull-left[ ] .pull-right[ .img75[] ] ??? You only need to set this configuration once in your computer Use the email of your Github account --- ## Git - Check the results Git config usethis::use_git_config(user.name = “User Name”, user.email = “email@email.com”) usethis::git_sitrep() .pull-left[ ] .pull-right[ .img75[] ] --- ## Git - Opens a browser window to the GitHub form to generate a PAT You can change the PAT’s name After you have created the PAT, copy the token Create a GitHub personal access token (PAT) usethis::create_github_token() The command will open the .Renviron file Insert the variable GITHUB_PAT and paste the token as it value: Restart R in RStudio: Ctrl-Shift-F10 Register the token in your computer usethis::edit_r_environ() .pull-left[ ] .pull-right[ .img75[] ] --- ## Git - Clone vs Fork Clone Fork --- ## Git - Clone: Exercise .pull-left[ Create a repository in GitHub, Name it: “first_repo”, Choose it visibility (in this case, we can set it to public) Select Add a README file Click Create repository ] .pull-right[ Create a new project in RStudio File > New Project > Version Control > Git Repository URL: Paste the GitHub repository URL Project directory name: is auto filled with the repository name, after you paste the URL Create project as subdirectory of: set the path of the local git repository Create a new R file Add some content and save it ] --- ## Git -Let’s push the changes to GitHub .pull-left[ Go to the Git tab Staged the file Click Commit Add a commit message Click Commit Click Push Refresh the repository website ] .pull-right[ .img75[] ] --- ## Git -Branches Before changing anything, create a branch: Create branch usethis::pr_init(branch = “branch_name") After that, update and add new files to the repository. Do not forget to commit your changes with descriptive and meaningful messages .pull-left[ ] .pull-right[ .img75[] ] --- ## Git - Create pull request (PR) pr_push() Once you're ready to submit, run pr_push() to push your local branch to GitHub: Source: usethis Opens a browser window to the GitHub Pull Request page Click “Create pull request” Add a message explaining the pull request content and click “Create pull request” Now the repository owner will evaluate your PR and if everything is alright, he/she will merge the PR to the master repo After the PR have been merged to the master repo, run pr_finish() to delete the local branch: Delete the local branch pr_finish() .pull-left[ ] .pull-right[ .img75[] ] --- ## Git - Practises Let`s work with the unhcr-git-exercise repository Activities Fork the repository Create branch Modify a file Commit the changes Create a pull request Exercise --- class: left, top # Good luck in your R journey! .pull-left[ __DIMA Americas__: <br> Check our github @ <a href="http://github.com/unhcr-americas"><i class="fa fa-github fa-fw"></i> unhcr-americas</a> and learn about __UnhcRverse packages__<br> Slides created with [**remark.js**](http://remarkjs.com/) and the R package [**xaringan**](https://github.com/yihui/xaringan). Slides notes for this presentation can be displayed by pressing keyboard shortcut `p` - Navigation help with keyboard shortcut `h` ] .pull-right[ <img src="data:image/png;base64,#img/giphy.gif" width="310px"/> ] --- class: inverse, center, middle # Thank you ### Questions? [post Feedback here](https://github.com/unhcRverse/unhcrverse/issues/new?assignees=&labels=enhancement&projects=&template=comment_prex_2_tidyverse.md&title=%5Blearn%5D) <a href="index.html"><i class="fa fa-indent fa-fw fa-2x"></i></a> --- ## Ressources - [Creating GitHub Portfolios](https://wd3.myworkday.com/unhcr/learning/course/16fc80c3079810011fc3d41e32520000?type=9882927d138b100019b928e75843018d) - [GitHub Actions for CI/CD](https://wd3.myworkday.com/unhcr/learning/course/db0ba7c05d98100035cf8c5c92240001?type=9882927d138b100019b928e75843018d)